package org.example.interceptor;

import org.example.exception.AuthApiException;
import org.example.exception.DefaultApiException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("user") == null) {
            throw new AuthApiException("请登录后再试");
        }
        return true;
    }
}
